﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using 报表导出.Common;
using 报表导出.Model;

namespace EasyUIDemo.MVC.Controllers
{
    public class pctureController : Controller
    {
        //
        // GET: /pcture/

        public ActionResult Index()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Dot(LZModel lz, FormCollection fc)
        {
            //实体接受不到数据，暂时用FormCollection
            lz = new LZModel();
            lz.XM = fc["XM"];
            lz.GS = fc["GS"];
            lz.LZ = Convert.ToDateTime(fc["LZ"]);
            lz.RZ = Convert.ToDateTime(fc["RZ"]);
            lz.GW = fc["GW"];


            //模板地址
            string TemplateName = Server.MapPath("\\Template\\离职证明.doc");

            //保存地址
            string SaveName = Server.MapPath(string.Format("\\Template\\离职证明{0}.doc", DateTime.Now.ToString("yyyyMMdd")));

            //模板内容
            List<WordsTemp> lwt = new List<WordsTemp>();
            lwt.Add(new WordsTemp() { Name = "姓名", Value = lz.XM });
            lwt.Add(new WordsTemp() { Name = "入年", Value = lz.RZ.Year.ToString() });
            lwt.Add(new WordsTemp() { Name = "入月", Value = lz.RZ.Month.ToString() });
            lwt.Add(new WordsTemp() { Name = "岗位", Value = lz.GW });
            lwt.Add(new WordsTemp() { Name = "离年", Value = lz.LZ.Year.ToString() });
            lwt.Add(new WordsTemp() { Name = "离月", Value = lz.LZ.Month.ToString() });
            lwt.Add(new WordsTemp() { Name = "离日", Value = lz.LZ.Day.ToString() });
            lwt.Add(new WordsTemp() { Name = "公司", Value = lz.GS });

            lwt.Add(new WordsTemp() { Name = "年", Value = DateTime.Now.Year.ToString() });
            lwt.Add(new WordsTemp() { Name = "月", Value = DateTime.Now.Month.ToString() });
            lwt.Add(new WordsTemp() { Name = "日", Value = DateTime.Now.Day.ToString() });

            CommonWords.Word(TemplateName, SaveName, lwt);

            return Content(string.Format("<script>location.href = '{0}';</script>", urlconvertor(SaveName)));
        }



        /// <summary>
        /// 本地路径转换成URL相对路径
        /// </summary>
        /// <param name="imagesurl1"></param>
        /// <returns></returns>
        private string urlconvertor(string imagesurl1)
        {
            string tmpRootDir = Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString());//获取程序根目录
            string imagesurl2 = imagesurl1.Replace(tmpRootDir, ""); //转换成相对路径
            imagesurl2 = imagesurl2.Replace(@"\", @"/");
            //imagesurl2 = imagesurl2.Replace(@"Aspx_Uc/", @"");
            return "/" + imagesurl2;
        }


        /// <summary>
        /// 格式化URL函数  urlX 传入相对URL objurl 传入绝对基URL  基URL 一定要带HTTP://
        /// </summary>
        /// <param name="urlX">传入单个的URL</param>
        /// <param name="objurl">
        /// 传入得到值的页面URL
        /// </param>
        /// <returns></returns>
        //public String FormAturl(String urlX, string objurl)
        //{
        //    Uri baseUri = new Uri(objurl); // http://www.enet.com.cn/enews/inforcenter/designmore.jsp
        //    Uri absoluteUri = new Uri(baseUri, urlX);//相对绝对路径都在这里转 这里的urlx ="../test.html"
        //    return absoluteUri.ToString();//   http://www.enet.com.cn/enews/test.html   
        //}
    
    }
}
